import vnode from "./vnode";
import createElement from "./createElement";
export default function (oldNode, newNode) {
  //判断oldNode是虚拟Dom还是Dom
  if (oldNode.sel == "" || oldNode.sel == undefined) {
    //将Dom节点包装为虚拟节点
    oldNode = vnode(oldNode.tagName.toLowerCase(), {}, [], undefined, oldNode);
  }
  //判断oldNode和newNode是不是同一个节点
  if (oldNode.sel == newNode.sel && oldNode.key == newNode.key) {
    console.log("是同一个节点");
  } else {
    //暴力插入新的，删除旧的
    console.log("不是同一个节点");
    console.log(oldNode);
    let newNodeElm = createElement(newNode);
    //插入到老节点之前
    oldNode.elm.parentNode.insertBefore(newNodeElm, oldNode.elm);
  }
}
